import { Injectable } from '@angular/core';
import { HttpService } from 'lbf';


@Injectable({
  providedIn: 'root',
})
export class RepserviceService {
  constructor(private lbservice: HttpService) { }

  url = null;

  getRep(repid: string, param: any) {
    let urlparam = '';
    return new Promise((fulfill, reject) => {
      this.lbservice
        .lbservice('repurl_query', { para: { REPID: repid } })
        .then(resdata => {
          //console.log(JSON.stringify(resdata));
          if (resdata.code === 1) {
            for (const key of Object.keys(param)) {
              if (param.hasOwnProperty(key)) {
                urlparam = urlparam + '&' + key + '=' + param[key];
                //console.log('urlparam===' + urlparam);
              }
            }
            // console.log('REPURL===' + resdata['message']['REPURL']);
            this.url = resdata['message']['REPURL'] + urlparam;
            // console.log('this.url===' + this.url);
          } else {
            this.url = null;
          }
          fulfill(this.url);
        });
    });
  }

}
